//
//  WebServiceApi.m
//  fa
//
//  Created by lj on 16/1/27.
//  Copyright © 2016年 lj. All rights reserved.
//

#import "FSRequest.h"
#import "AFNetworking.h"
#include <stdint.h>
#import <ifaddrs.h>
#import <arpa/inet.h>
#import <net/if.h>

#import "FSRequestModel.h"

#define TIME_OUT                20

static id handleSerializeJsonObject(Class resultClass, id jsonObject) {
    if([resultClass isSubclassOfClass:[BizMObject class]]) {
        if([jsonObject isKindOfClass:[NSDictionary class]]) {
            return [[resultClass class] serializeWithJsonObject:jsonObject];
        }
        
        if([jsonObject isKindOfClass:NSArray.class]) {
            return [[resultClass class] serializeWithJsonObjects:jsonObject];
        }
    }
    
    return jsonObject;
}



@interface FSRequest ()

/**
 *  用来写数据的文件句柄对象
 */
@property (nonatomic, strong) NSFileHandle *writeHandle;

/**
 *  文件的总长度
 */
@property (nonatomic, assign) long long totalLength;
/**
 *  当前已经写入的总大小
 */
@property (nonatomic, assign) long long  currentLength;
/**
 *  连接对象
 */
@property (nonatomic, strong) NSURLConnection *connection;

@property (nonatomic, weak) void (^failure)(NSString *error);
@property (nonatomic, weak) void (^successBlock)(NSString *downLoadFilePath);
@property (nonatomic, weak) void (^progress)(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite);

@property (nonatomic, assign) int trafficBytes;
//@property (nonatomic, strong) DataTrafficPacket *trafficPacket;

@property (nonatomic, strong) AFHTTPSessionManager *manager;

@end


@implementation FSRequest

SHARED_SERVICE(FSRequest);

- (id)init {
    self = [super init];
    if (self) {
        
        AFSecurityPolicy *securityPolicy = [AFSecurityPolicy defaultPolicy];
        securityPolicy.allowInvalidCertificates = YES;
        securityPolicy.validatesDomainName = NO;
        
        _manager = [AFHTTPSessionManager manager];
        _manager.securityPolicy = securityPolicy;
        _manager.requestSerializer.timeoutInterval = TIME_OUT;
        _manager.responseSerializer = [AFHTTPResponseSerializer serializer];
        _manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/JavaScript",@"text/html",@"text/plain",@"charset=utf-8",@"multipart/form-data", nil];
    }
    return self;
}

+ (NSString *)urlWithServer:(NSString*)server andPath:(NSString *)path {
    NSString *url = nil;
    if ([path hasPrefix:@"http://"] || [path hasPrefix:@"https://"]) {
        url = path;
    }
    else if (0 == path.length) {
        url = [NSString stringWithFormat:@"%@", server];
    }
    else {
        url = [NSString stringWithFormat:@"%@%@", server, path];
    }
    return url;
}

- (void)bodyPostRequestWithPath:(NSString *)path withBodyParams:(id)bodyParams withHeaders:(NSDictionary *)headers withResultClass:(Class)resultClass withSuccess:(FSRequestSuccessBlock)successBlock withFail:(FSRequestFailBlock)failBlock {
    [self requestWithMethod:@"POST" withPath:path withParams:@{} withBodyParams:bodyParams withHeaders:headers withResultClass:resultClass withSuccess:successBlock withFail:failBlock];
}

- (void)bodyGetRequestWithMethod:(NSString *)method withPath:(NSString *)path withBodyParams:(NSDictionary *)bodyParams withHeaders:(NSDictionary *)headers withResultClass:(Class)resultClass withSuccess:(FSRequestSuccessBlock)successBlock withFail:(FSRequestFailBlock)failBlock {
    [self requestWithMethod:@"GET" withPath:path withParams:@{} withBodyParams:bodyParams withHeaders:headers withResultClass:resultClass withSuccess:successBlock withFail:failBlock];
}

- (void)requestWithMethod:(NSString *)method withPath:(NSString *)path withParams:(NSDictionary *)params withBodyParams:(NSDictionary *)bodyParams withHeaders:(NSDictionary *)headers withResultClass:(Class)resultClass withSuccess:(FSRequestSuccessBlock)successBlock withFail:(FSRequestFailBlock)failBlock {
    //    NSString *url = [FSRequest urlWithServer:SERVER andPath:path];
        NSString *url;
    url = [FSRequest urlWithServer:SERVER andPath:path];
    

    NSString *requestUrl = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    KSLog(@"上传路径 --- %@    上传参数： %@ ",url,bodyParams);
    
    NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] requestWithMethod:method URLString:requestUrl parameters:params error:nil];
    request.timeoutInterval= TIME_OUT;
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-type"];
    for (NSString *headerField in headers.keyEnumerator) {
        [request setValue:[NSString stringWithFormat:@"%@",headers[headerField]] forHTTPHeaderField:headerField];
    }
    
    [request setValue:@"ios" forHTTPHeaderField:@"appType"];
//    [request setValue:[FSUserModel readUserDataWithKey:kFS_Login_Data].token?:@"" forHTTPHeaderField:@"token"];
    [request setValue:[self getVersionString] forHTTPHeaderField:@"appVersion"];
    KSLog(@"%@",[[UIDevice currentDevice].identifierForVendor UUIDString]);
    [request setValue:[[UIDevice currentDevice].identifierForVendor UUIDString] forHTTPHeaderField:@"equipment"];
    
    
    if (bodyParams.count) {
        // 设置body
        NSData *data = [NSJSONSerialization dataWithJSONObject:bodyParams options:NSJSONWritingPrettyPrinted error:nil];
        [request setHTTPBody:data];
    }

    AFHTTPResponseSerializer *responseSerializer = [AFHTTPResponseSerializer serializer];
    responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/html", @"text/json", @"text/javascript", @"text/plain", nil];
    self.manager.responseSerializer = responseSerializer;
    
    MJWeakSelf
    [[self.manager dataTaskWithRequest:request uploadProgress:^(NSProgress * _Nonnull uploadProgress) {
    
    } downloadProgress:^(NSProgress * _Nonnull downloadProgress) {
        
    } completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
        if (!error) {
            [weakSelf bodyRequestSuccessWithResponse:response withObject:responseObject withResultClass:resultClass withSuccess:successBlock withFail:failBlock];
        }
        else {
            [weakSelf bodyRequestFailWithResponse:response withObject:responseObject withError:error withFail:failBlock];
            KSLog(@"%@",[NSString stringWithFormat:@"错误:get_%@\n错误信息:%@\n消息头:%@\n参数:%@\n",path,error.description,weakSelf.manager.requestSerializer.HTTPRequestHeaders, params]);
        }
    }] resume];
}

- (void)requestSuccessResultWithTask:(NSURLSessionDataTask *)task withResponse:(id)responseObject withResultClass:(Class)resultClass withSuccess:(FSRequestSuccessBlock)successBlock withFail:(FSRequestFailBlock)failBlock {
    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response;
    NSInteger statusCode = httpResponse.statusCode;
    if (statusCode == 401) {
        failBlock(401, @"请重新登录", responseObject);
        [self nav_PushLogin];
        return;
    }
    
    FSRequestModel *model = [FSRequestModel modelWithJSON:responseObject];
    
    NSArray *codes;
    if ([model.code containsString:@"-"]) {
        codes = [model.code componentsSeparatedByString:@"-"];
    }
    else if ([model.code containsString:@"_"]) {
        codes = [model.code componentsSeparatedByString:@"_"];
    }

    NSInteger code = 0;
    if (codes.count > 0) {
        code = [[codes lastObject] integerValue];
    }
    else {
        code = [model.code integerValue];
    }
    
    if (statusCode == 403) {
        model.message = @"无权限";
    }
    
    KSLog(@"后台返回---------   %@",model.content);
    
    if (code == CODE_SUCCESS) {
        if (resultClass == nil) {
            successBlock(code, model.message, model.content);
        }
        else if ([model.content isKindOfClass:[NSArray class]]) {
            successBlock(code, model.message, [NSArray modelArrayWithClass:resultClass json:model.content]);
        }
        else if ([model.content isKindOfClass:[NSDictionary class]]) {
            successBlock(code, model.message, [resultClass modelWithJSON:model.content]);
        }
        else {
            successBlock(code, model.message, model.content);
        }
    }
    else if (code == CODE_TOKEN_INVALID) {
        failBlock(code, model.message, model.content);
    }
    else {
        failBlock(code, model.message, model.content);
    }
}

- (void)requestFailResultWithTask:(NSURLSessionDataTask *)task withError:(NSError *)error withFail:(FSRequestFailBlock)failBlock {
    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response;
    NSString *errorDomain = error.domain;
    if ([errorDomain isEqualToString:AFURLResponseSerializationErrorDomain]) {
        id response = [NSJSONSerialization JSONObjectWithData:error.userInfo [AFNetworkingOperationFailingURLResponseDataErrorKey] options:0 error:nil];
        if ([response isKindOfClass:[NSDictionary class]]) {
            KSLog(@"request fail: code is %@ and message is %@",response[@"code"],response[@"msg"]);
        }
    }
    
    NSInteger statusCode = httpResponse.statusCode;
//    NSHTTPURLResponse * responses = (NSHTTPURLResponse *)task.response;
//    NSData *data = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
//    id body = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
//    NSLog(@"%@", body);
    
    CZLErrMsg *err = [self failureHandlerCenter:error];
    
    if (statusCode == 401) {
        failBlock(401, @"请重新登录", error);
        [self nav_PushLogin];
        return;
    }
    else if (statusCode == 403) {
        err.errorMessage = @"无权限";
    }
    failBlock(err.errorCode, err.errorMessage, err);
}

- (void)bodyRequestSuccessWithResponse:(NSURLResponse *)response withObject:(id)responseObject withResultClass:(Class)resultClass withSuccess:(FSRequestSuccessBlock)successBlock
                      withFail:(FSRequestFailBlock)failBlock {
    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
    if (httpResponse.statusCode == 401) {
        failBlock(401, @"请重新登录", responseObject);
        [self nav_PushLogin];
        return;
    }
    
    FSRequestModel *model = [FSRequestModel modelWithJSON:responseObject];
    
    NSArray *codes;
    if ([model.code containsString:@"-"]) {
        codes = [model.code componentsSeparatedByString:@"-"];
    }
    else if ([model.code containsString:@"_"]) {
        codes = [model.code componentsSeparatedByString:@"_"];
    }
    NSInteger code = 0;
    if (codes.count > 0) {
        code = [[codes lastObject] integerValue];
    }
    else {
        code = [model.code integerValue];
    }
    
    KSLog(@"后台返回---------   %@",model.content);
    KSLog(@"后台返回---------message--   %@",model.message);
    
    if (httpResponse.statusCode == 403) {
        model.message = @"无权限";
    }
    
    if (code == CODE_SUCCESS) {
        if (resultClass == nil) {
            successBlock(code, model.message, model.content);
        }
        else if ([model.content isKindOfClass:[NSArray class]]) {
            successBlock(code, model.message, [NSArray modelArrayWithClass:resultClass json:model.content]);
        }
        else if ([model.content isKindOfClass:[NSDictionary class]]){
            successBlock(code, model.message, [resultClass modelWithJSON:model.content]);
        }
        else {
            successBlock(code, model.message, model.content);
        }
    }
    else if (code == CODE_TOKEN_INVALID) {
        failBlock(code, model.message, model.content);
    }
    else {
        failBlock(code, model.message, model.content);
    }
}

- (void)bodyRequestFailWithResponse:(NSURLResponse *)response withObject:(id)responseObject withError:(NSError *)error withFail:(FSRequestFailBlock)failBlock  {
    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
    
    NSDictionary *dic = [NSDictionary dictionaryWithJSON:responseObject];
    if ([dic isKindOfClass:[NSDictionary class]]) {
        KSLog(@"request fail: code is %@ and message is %@",dic[@"code"],dic[@"msg"]);
    }
    
    CZLErrMsg *err = [self failureHandlerCenter:error];
    if (httpResponse.statusCode == 401) {
        failBlock(401, @"请重新登录", error);
        [self nav_PushLogin];
    }
    else if (httpResponse.statusCode == 403) {
        err.errorMessage = @"无权限";
    }
    failBlock(err.errorCode, err.errorMessage, err);
}

- (void)getRequestWithPath:(NSString *)pathString
                    params:(NSMutableDictionary *)params
                   headers:(NSMutableDictionary *)headers
               resultClass:(Class)resultClass
                   success:(FSRequestSuccessBlock)successBlock
                      fail:(FSRequestFailBlock)failBlock {
       NSString *url = [FSRequest urlWithServer:SERVER andPath:pathString];

    NSString *tempUrlStr = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    [self setupHttpHeader:headers];
    
    KSLog(@"上传路径 --- %@/n上传参数： %@ ",url,params);
    MJWeakSelf
    [self.manager GET:tempUrlStr parameters:params headers:headers progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [weakSelf requestSuccessResultWithTask:task withResponse:responseObject withResultClass:resultClass withSuccess:successBlock withFail:failBlock];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [weakSelf requestFailResultWithTask:task withError:error withFail:failBlock];
    }];
}

- (void)postRequestWithPath:(NSString *)pathString
                     params:(NSMutableDictionary *)params
                    headers:(NSMutableDictionary *)headers
                resultClass:(__unsafe_unretained Class)resultClass
                     success:(FSRequestSuccessBlock)successBlock
                      fail:(FSRequestFailBlock)failBlock {
    NSString *url = [FSRequest urlWithServer:SERVER andPath:pathString];
    KSLog(@"上传路径 --- %@   上传参数： %@ ",url,params);
    NSString *tempUrlStr = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    NSString *loginUrl = [NSString stringWithFormat:@"%@/emp/login",API_EMP_URL];
    
    if (![pathString isEqualToString:loginUrl]) {//登录接口需不需要head
         [self setupHttpHeader:headers];
    }
    
    MJWeakSelf
    [self.manager POST:tempUrlStr parameters:params headers:headers?:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [weakSelf requestSuccessResultWithTask:task withResponse:responseObject withResultClass:resultClass withSuccess:successBlock withFail:failBlock];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [weakSelf requestFailResultWithTask:task withError:error withFail:failBlock];
    }];
}

- (void)putRequestWithPath:(NSString *)pathString
                    params:(NSMutableDictionary *)params
                   headers:(NSMutableDictionary *)headers
               resultClass:(__unsafe_unretained Class)resultClass
                    success:(FSRequestSuccessBlock)successBlock
                      fail:(FSRequestFailBlock)failBlock {
    
        NSString *url = [FSRequest urlWithServer:SERVER andPath:pathString];
        
    NSString *tempUrlStr = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    [self setupHttpHeader:headers];
    
    MJWeakSelf
    [_manager PUT:tempUrlStr parameters:params headers:headers success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [weakSelf requestSuccessResultWithTask:task withResponse:responseObject withResultClass:resultClass withSuccess:successBlock withFail:failBlock];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [weakSelf requestFailResultWithTask:task withError:error withFail:failBlock];
    }];
}

- (void)deleteRequestWithPath:(NSString *)pathString
                       params:(NSMutableDictionary *)params
                      headers:(NSMutableDictionary *)headers
                  resultClass:(__unsafe_unretained Class)resultClass
                       success:(FSRequestSuccessBlock)successBlock
                      fail:(FSRequestFailBlock)failBlock {
    NSString *url = [FSRequest urlWithServer:SERVER andPath:pathString];
    NSString *tempUrlStr = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    [self setupHttpHeader:headers];
    
    MJWeakSelf
    [_manager DELETE:tempUrlStr parameters:params headers:headers success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [weakSelf requestSuccessResultWithTask:task withResponse:responseObject withResultClass:resultClass withSuccess:successBlock withFail:failBlock];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [weakSelf requestFailResultWithTask:task withError:error withFail:failBlock];
    }];
}

#pragma mark - 上传图片的接口
- (void)uploadImageWithPath:(NSString *)pathString
                     params:(NSMutableDictionary *)params
                     images:(NSArray *)images
                  imageName:(NSString *)imageName
                resultClass:(Class)resultClass
                     success:(FSRequestSuccessBlock)successBlock
                      fail:(FSRequestFailBlock)failBlock {
    NSString *url = [FSRequest urlWithServer:SERVER andPath:pathString];
    NSString *tempUrlStr = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [self.manager.requestSerializer setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-type"];
    MJWeakSelf
    [self.manager POST:tempUrlStr parameters:params headers:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        NSInteger size = (1000 * 1000 * 2) / images.count;
        
        if (size > 500 * 1000) {
            size = 500 * 1000;
        }
        
        for (NSInteger i = 0; i < images.count; i++) {
            UIImage *image = images[i];
            NSData *imageData = [image imageCompressWithDataMaxLength:size];
            [formData appendPartWithFileData:imageData name:[NSString stringWithFormat:@"file[%ld],%@",(long)i,imageName] fileName:[NSString stringWithFormat:@"%@.jpg",imageName] mimeType:@".jpg"];
        }
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [weakSelf requestSuccessResultWithTask:task withResponse:responseObject withResultClass:resultClass withSuccess:successBlock withFail:failBlock];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [weakSelf requestFailResultWithTask:task withError:error withFail:failBlock];
    }];
}



- (CZLErrMsg *)failureHandlerCenter:(id)error {
    NSInteger errorCode = 0;
    NSString *fromNetErr = @"";
    if ([error isKindOfClass:[NSError class]]) {
        NSError *tempError = (NSError *)error;
        errorCode = tempError.code;
    }else if ([error isKindOfClass:[NSDictionary class]]){
        NSDictionary *errorInfo = (NSDictionary *)error;
        errorCode = [[errorInfo objectForKey:@"code"] integerValue];
        fromNetErr = [errorInfo objectForKey:@"msg"];
    }
    
    NSString *errorStr = @"";
    switch (errorCode) {
        case NET_CAN_NOT_USE:
            errorStr = @"请求超时,请稍后再试";
            break;
        case TOKEN_INVALID:
            break;
        case FRIEND_NOTEXIST:
            //            errorStr = @"当前用户暂无好友或网络超时，请稍后再试！";
            break;
        default://未知错误
            errorStr = fromNetErr.length>0?fromNetErr:@"请求失败";//tocken失效
            break;
    }
    CZLErrMsg *err = [[CZLErrMsg alloc] init];
    err.errorCode = NET_CAN_NOT_USE;
    err.errorMessage = errorStr;
    return err;
}

- (void)setupHttpHeader:(NSDictionary *)headers {
    [self.manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-type"];
    [self.manager.requestSerializer setValue:@"ios" forHTTPHeaderField:@"appType"];
//    [self.manager.requestSerializer setValue:[FSUserModel readUserDataWithKey:kFS_Login_Data].token?:@"" forHTTPHeaderField:@"token"];
    [self.manager.requestSerializer setValue:[self getVersionString] forHTTPHeaderField:@"appVersion"];
     KSLog(@"%@",[[UIDevice currentDevice].identifierForVendor UUIDString]);
    [self.manager.requestSerializer setValue:[[UIDevice currentDevice].identifierForVendor UUIDString] forHTTPHeaderField:@"equipment"];

    for (NSString *headerField in headers.keyEnumerator) {
        [self.manager.requestSerializer setValue:[NSString stringWithFormat:@"%@",headers[headerField]] forHTTPHeaderField:headerField];
    }
}

//获取当前屏幕显示的UIViewController
- (UIViewController *)getCurrentVC {
    UIViewController *result = nil;
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    if (window.windowLevel != UIWindowLevelNormal) {
        NSArray *windows = [[UIApplication sharedApplication] windows];
        for(UIWindow *tmpWin in windows) {
            if (tmpWin.windowLevel == UIWindowLevelNormal) {
                window = tmpWin;
                break;
            }
        }
    }
    
    UIView *frontView = [[window subviews] objectAtIndex:0];
    id nextResponder = [frontView nextResponder];
    
    if ([nextResponder isKindOfClass:[UIViewController class]])
        result = nextResponder;
    else
        result = window.rootViewController;
    
    return result;
}

- (void)cancelRequest
{
    if ([_manager.tasks count] > 0) {
        NSLog(@"返回时取消网络请求");
        [_manager.tasks makeObjectsPerformSelector:@selector(cancel)];
        //NSLog(@"tasks = %@",manager.tasks);
    }
}

-(NSString *)getVersionString{

    //此获取的版本号对应version，打印出来对应为1.2.3.4.5这样的字符串
    NSString *string = [NSString stringWithFormat:@"%@",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]];
    return string;
}

- (void)nav_PushLogin {
    
//    FSBaseVC *currentVc = (FSBaseVC *)[MyAppDelegate getCurrentUIVC];
//    if ([currentVc isKindOfClass:[FSLoginRootVC class]]) {
//        return;
//    }
//    NSMutableArray *currentVcs = currentVc.navigationController.viewControllers.mutableCopy;
//    if ([[currentVcs lastObject] isKindOfClass:[FSLoginRootVC class]]) {
//        return;
//    }
//    MBError(@"请重新登录");
//
//    KSLog(@"重新登录。。。。。");
//
//    FSLoginRootVC *loginVc = [[FSLoginRootVC alloc] init];
//    if ([[MyAppDelegate getCurrentUIVC] isKindOfClass:[FSBaseVC class]]) {
//        [(FSBaseVC *)[MyAppDelegate getCurrentUIVC] pushAndHiddenBottomBarToVC:loginVc];
//    }
//    else {
//        [[MyAppDelegate getCurrentUIVC].navigationController pushViewController:loginVc animated:YES];
//    }
    
//    loginVc.hidesBottomBarWhenPushed = YES;
//    [currentVcs addObject:loginVc];
//    [currentVc.navigationController setViewControllers:currentVcs animated:YES];
//    [currentVc pushAndHiddenBottomBarToVC:loginVc];
}

@end
